/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.common;

import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Element;

import com.edi.Constant;
import com.edi.db.cfg.Configuration;

/**
 * 服务器配置文件，读取edi.xml后形成
 * 
 * @author 红木
 * 
 */
public class ServerConfigure extends Configuration {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7754297440199126216L;

	private static final Log log = LogFactory.getLog(ServerConfigure.class);

	//	private Element wapEs;

	public ServerConfigure(String filePath) throws Exception {
		super(filePath);
	}

	public ServerConfigure(Document document) throws Exception {
		super(document);
	}

	public Configuration configutation(Document doc) {
		Element kola = doc.getRootElement();
		Element dbConfig = kola.element("dbconfig");

		//读取数据库属性
		Iterator<Element> i = dbConfig.elementIterator("prop");
		while (i.hasNext()) {
			Element prop = i.next();
			String id = prop.attributeValue("id");
			String value = prop.attributeValue("value");

			if (!id.startsWith("edidb"))
				properties.setProperty("edidb." + id, value);
			else
				properties.setProperty(id, value);
		}

		
		this.setProperties(Constant.CLIENT_DEBUG, kola
				.elementText("clientDebug"), Constant.CLIENT_DEBUG_DVALUE);
		
		this
				.setProperties(Constant.VERSION_DES, kola
						.elementText(Constant.VERSION_DES),
						Constant.VERSION_DES_FORMAL);

		return this;
	}
}
